package jp.wug.samples.export;

import com.google.inject.Inject;
import com.google.inject.servlet.RequestScoped;
import jp.wug.PageFlow;

@RequestScoped
class Status {
    private final PageFlow pageFlow;
    private int editingTreeId = -1;

    @Inject
    Status(PageFlow pageFlow) {
        this.pageFlow = pageFlow;
    }

    public int getEditingTreeId() {
        return editingTreeId;
    }

    public void setEditingTreeId(int editingTreeId) {
        this.editingTreeId = editingTreeId;
    }

    boolean isEditing() {
        return editingTreeId != -1;
    }

    boolean isEditing(Tree tree) {
        return editingTreeId == tree.getId();
    }

    void edit(Tree tree) {
        editingTreeId = tree.getId();
        pageFlow.redirectTo();
    }

    void doneEditing(Tree tree) {
        assert isEditing(tree);
        editingTreeId = -1;
        pageFlow.redirectTo();
    }
}
